const webpack = require("webpack");
const path = require("path");
const fs = require('fs');

const resolve = require("./driver").resolve;
const webpackPromise = require("./driver").webpackPromise;

const dir = require('./dir');

let action = process.argv.length == 5 ? process.argv[process.argv.length - 3] : process.argv[process.argv.length - 2];
let source_path = process.argv.length == 5 ? process.argv[process.argv.length - 2] : process.argv[process.argv.length - 1];
let app = process.argv.length == 5 ? process.argv[process.argv.length - 1] : '';
(async function() {
  console.log(`\n执行 ${action} ${source_path} ...`);

  let file = path.join(dir.frameworkDir, 'webpack', `webpack.${action}.js`);

  if (!fs.existsSync(file)) {
    console.log(`文件未找到：${file}`);
    return;
  }

  let runner = require(file);

  await runner(source_path, app);

})().then(() => {
  console.log(`\n结束 ${action} ${source_path} ...`);
});
